package org.itsky.study.test1;

import java.security.PublicKey;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Predicate;

/**
 * @Author sky
 * @Site cmtianxie163.com 2020/4/10 22:00
 */
public class LambdaTest4 {
    public static void main(String[] args) {
        happyMoney(100, m -> System.out.println("今天花了"+m));

        List<String> list = Arrays.asList("北京", "上海", "南京", "六安", "合肥", "东京");
        List<String> list1 = filterString2(list, s -> s.contains("京"));
        System.out.println(list1);
    }

    static void happyMoney(double money, Consumer<Double> con){
        con.accept(money);
    }

    static List<String> filterString(List<String> list, Predicate<String> pre){
        List<String> newlist = new ArrayList<>();
        for (String s : list) {
            if (pre.test(s)){
                newlist.add(s);
            }
        }
        return newlist;
    }

    static List<String> filterString2(List<String> list, Predicate<String> pre){
        List<String> newlist = new ArrayList<>();
        list.forEach(s -> {if (pre.test(s)){
            newlist.add(s);
        }});
        return newlist;
    }
}
